package sanshi.contect.singlet;

/**
 * 使用静态内部类的形式。
 */
public class Singleton3 {

    private Singleton3(){

    }
    //静态内部类
    public static class SingletonHolder{
        private static final Singleton3 INSTANCE = new Singleton3();
    }
    //在外部类中定义返回实例的方法
    public static Singleton3 getInstance(){
        return SingletonHolder.INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(() -> System.out.println(Singleton3.getInstance().hashCode())).start();
        }
    }
}
